#include "lom-instance-factory.hh"
#include "lom-instance-manager.hh"
#include "lom-value-factory.hh"
#include "lom-instance.hh"

namespace lom
{
    void LomInstanceFactory::setup( ILomInstanceManager* _instanceMgr
				    , ILomValueFactory* _valueFactory
				    , ILomEventSystem* _eventSys )
    {
	instanceMgr = _instanceMgr;
	valueFactory = _valueFactory;
	eventSys = _eventSys;
    }
    
    THandle LomInstanceFactory::reserveHandle()
    {
	return instanceMgr->reserveHandle();
    }

    THandle LomInstanceFactory::createInstance( const LomClass* cls, THandle reserveHandle ) {
	LomInstance* retval = new LomInstance( cls, valueFactory, instanceMgr, reserveHandle );
	retval->setEventHandler( eventSys );
	return retval->getHandle();
    }
    
    THandle LomInstanceFactory::createInstance( const LomInstance& inst
						, THandle reserveHandle )
    {
	LomInstance* retval = new LomInstance( inst, valueFactory, instanceMgr, reserveHandle );
	retval->setEventHandler( eventSys );
	return retval->getHandle();
    }
}
